<?php
namespace BP\GPM;
require_once("BP/En/Map.php");
class AppSort extends EntityNoName {
	public function getRefMenuNo () 
	{
		return $this->GetValStrByKey(AppSortAttr::$RefMenuNo);
	}
	public function setRefMenuNo ($value) // [String value]
	{
		$this->SetValByKey(AppSortAttr::$RefMenuNo, $value);
	}
	public function getHisUAC () 
	{
		$uac = new UAC();
		$uac->OpenForAppAdmin();
		return $uac;
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($no) // [String no]
	{
		$me = new self();
		$me->setNo($no);
		$me->Retrieve();
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("GPM_AppSort", "系统类别");
		$map->setIsAutoGenerNo( TRUE );
		$map->AddTBStringPK(AppSortAttr::$No, NULL, "编号",  TRUE ,  TRUE , 2, 2, 20);
		$map->AddTBString(AppSortAttr::$Name, NULL, "名称",  TRUE ,  FALSE , 0, 300, 20);
		$map->AddTBInt(AppSortAttr::$Idx, 0, "显示顺序",  TRUE ,  FALSE );
		$map->AddTBString(AppSortAttr::$RefMenuNo, NULL, "关联的菜单编�?",  FALSE ,  FALSE , 0, 300, 20);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	protected function beforeDelete () 
	{
		$pps = Apps::constructor__();
		$pps->Retrieve(AppAttr::$FK_AppSort, $this->getNo());
		if (($pps->size() != 0))
		{
			throw new \RuntimeException("err@该类别下有系统，您不能删除，请把该系统类别下的系统移除或者删除，您才能删除该类别�?");
		}
		$root = Menu::constructor__();
		$root->setNo($this->getRefMenuNo());
		if (($root->RetrieveFromDBSources() > 0))
		{
			$root->Delete();
		}
		return parent->beforeDelete();
	}
	protected function beforeUpdate () 
	{
		$root = Menu::constructor__();
		$root->setNo($this->getRefMenuNo());
		if (($root->RetrieveFromDBSources() > 0))
		{
			$root->setName($this->getName());
			$root->Update();
		}
		return parent->beforeUpdate();
	}
	protected function beforeInsert () 
	{
		parent->beforeInsert();
		$root = Menu::constructor__();
		$root->setNo("1000");
		if (($root->RetrieveFromDBSources() == 0))
		{
			$root->setParentNo("0");
			$root->setName(SystemConfig::getSysName());
			$root->setFK_App(SystemConfig::getSysNo());
			$root->setHisMenuType(MenuType::$Root);
			$root->setIdx(0);
			$root->Insert();
		}
		$tempVar = $root->DoCreateSubNode();
		$sort1 = ( ($tempVar instanceof Menu) ? $tempVar : NULL );
		$sort1->setName($this->getName());
		$sort1->setHisMenuType(MenuType::$AppSort);
		$sort1->setFK_App("AppSort");
		$sort1->Update();
		$this->setRefMenuNo($sort1->getNo());
		return  TRUE ;
	}
}
?>
